<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%
// 파라미터 catergory 받아옴 -> 주소뒤에 ?category='' <-- 이걸 받아온다는 뜻
String category = request.getParameter("category");
// team_no 는 일단 빈문자열로 지정
String team_no = "";
// 파라미터 team_no 가 있을시 값 대체 아니면 ""이걸로 쭉감
if(!"".equals(request.getParameter("team_no")) || null != request.getParameter("team_no")){
	team_no = request.getParameter("team_no");
}
%>
<script language="javascript">
	function searchCheck(){
		
		if(document.forms[1].keyWord.value==''){
			return true;
		} else{
			return false;
		}
	}
	
	//검색 버튼 클릭시 오는 함수
	function goSearch(){
		//f = 전체문서의 첫번쨰 폼
		var f = document.forms[1];
		if(f.keyWord.value==''){
			alert('검색어를 입력하세요');
			f.keyWord.focus();
			//return은 현재 여기서 멈추라는 뜻.
			return;
		}
		
		f.submit();
		
	}
	function goWrite() {
		var f = document.forms[0];
		var team = f.team_no.value;
		var category = f.category.value;
		if (category == 'gong' || category == 'jung' || category == 'gallery') {
			var url = '/seoul-javas/board/write.do?category=' + category
					+ '&team_no=';
		} else if (category == 'yagu') {
			var url = '/seoul-javas/board/write.do?category=' + category
					+ '&team_no=' + team;
		}

		location.href = url;
	}

	function checkId() {
		alert('로그인 해주세용~~~');
		location.href = '/seoul-javas/login.do';
	}
	
	function loadFunction(){
		var f = document.forms[1];
		var headDiv = document.getElementById('team1');
		category = f.category_old.value;
		if(category == 'yagu'){
			headDiv.style.visibility = "visible";
			
		}
	}
	
</script>

<!-- 
	form action 을 줫으니
	그거에 맞게 위에서..확인..
	f.submit()은 선언된 폼에 action을 실행하는것
 -->
<br>
<c:if test="${category == 'yagu'}">
<img src="../c-images/yagu1.jpg" width="100%" height="" align="center"></img>
</c:if>
<c:if test="${category == 'gong'}">
<img src="../c-images/gong1.jpg" width="100%" height="" align="center"></img>
</c:if>
<c:if test="${category == 'jung'}">
<img src="../c-images/jung1.jpg" width="100%" height="" align="center"></img>
</c:if>
<c:if test="${category == 'gallery'}">
<img src="../c-images/gallery1.jpg" width="100%" height="" align="center"></img>
</c:if>
<br><br><br>

<body onload="loadFunction();">
<table width="100%" border="0" cellspacing="1" cellpadding="2" >
<form>
		<c:if test="${category == 'gong'}">
			<tr bgcolor="#333">
				<th width="50"><font color="#FFFFFF">번호</font></th>
				<th><font color="#FFFFFF">제목</font></th>
				<th width="70"><font color="#FFFFFF">글쓴이</font></th>
				<th width="100"><font color="#FFFFFF">날짜</font></th>
				<th width="70"><font color="#FFFFFF">조회수</font></th>
			</tr>
		</c:if>
		<c:if test="${category == 'jung'}">
			<tr bgcolor="#333">
				<th width="50"><font color="#FFFFFF">번호</font></th>
				<th><font color="#FFFFFF">제목</font></th>
				<th width="70"><font color="#FFFFFF">글쓴이</font></th>
				<th width="100"><font color="#FFFFFF">날짜</font></th>
				<th width="70"><font color="#FFFFFF">조회수</font></th>
			</tr>
		</c:if>
		<c:if test="${category == 'yagu'}">
			<tr bgcolor="#333">
				<th width="50"><font color="#FFFFFF">번호</font></th>
				<th width="120"><font color="#FFFFFF">팀명</font></th>
				<th><font color="#FFFFFF">제목</font></th>
				<th width="70"><font color="#FFFFFF">글쓴이</font></th>
				<th width="100"><font color="#FFFFFF">날짜</font></th>
				<th width="70"><font color="#FFFFFF">조회수</font></th>
			</tr>
		</c:if>
		<c:if test="${count==0 }">
			<tr>
				<td colspan="5" align="center">등록된 게시물이 없습니다.</td>
			</tr>
		</c:if>
		<c:if test="${category == 'gong'}">
			<c:forEach var="article" items="${list }">
				<tr>
					<td align="center">${article.bo_num }</td>
					<td><c:if test="${empty userId}">
							<a href="/seoul-javas/login.do" onclick="checkId()">${article.bo_title }</a>
						</c:if> <c:if test="${!empty userId}">
							<a href="detail.do?bo_num=${article.bo_num}">${article.bo_title }</a>
						</c:if>
					<td>${article.bo_id }</td>
					<td>${article.bo_today }</td>
					<td align="center">${article.bo_count }</td>
				</tr>
			</c:forEach>
		</c:if>
		<c:if test="${category == 'jung'}">
			<c:forEach var="article" items="${list }">
				<tr>
					<td align="center">${article.bo_num }</td>
					<td><c:if test="${empty userId}">
							<a href="/seoul-javas/login.do" onclick="checkId()">${article.bo_title }</a>
						</c:if> <c:if test="${!empty userId}">
							<a href="detail.do?bo_num=${article.bo_num}">${article.bo_title }</a>
						</c:if></td>
					<td>${article.bo_id }</td>
					<td>${article.bo_today }</td>
					<td align="center">${article.bo_count }</td>
				</tr>
			</c:forEach>
		</c:if>
		<c:if test="${category == 'yagu' }">
			<c:forEach var="article" items="${list }">
				<tr>
					<td align="center">${article.bo_num }</td>
					<td align="center">${article.team_name }</td>
					<td><c:if test="${empty userId}">
							<a href="/seoul-javas/login.do" onclick="checkId()">${article.bo_title }</a>
						</c:if> <c:if test="${!empty userId}">
							<a href="detail.do?bo_num=${article.bo_num}">${article.bo_title }</a>
						</c:if></td>
					<td>${article.bo_id }</td>
					<td>${article.bo_today }</td>
					<td align="center">${article.bo_count }</td>
				</tr>
			</c:forEach>
		</c:if>
		<c:if test="${category == 'gallery' }">
			<tr>
				<c:forEach var="article" items="${list }" varStatus="i">
					<td align="center"><c:if test="${empty userId}">
							<a href="/seoul-javas/login.do" onclick="checkId()"> <img
								src="../upload/${article.bo_image }" width="150px"
								height="200px"><br> ${article.bo_title }
							</a>
						</c:if> <c:if test="${!empty userId}">
							<a href="detail.do?bo_num=${article.bo_num}"> <img
								src="../upload/${article.bo_image }" width="150px"
								height="200px"><br> ${article.bo_title }
							</a>
						</c:if><br> 작성자 : <b><font color="blue">${article.bo_id }</font></b><br>
						조회수 : <b><font color="red">${article.bo_count }</font></b></td>
					<c:if test="${i.index%5 == 4}">
						</tr><tr>
					</c:if>
				</c:forEach>
			</tr>
		</c:if>
		<tr>
			<td align="right" colspan="5">
				<c:if test="${empty userId}">
					<input type="button" value="글쓰기" onclick="checkId()" />
				</c:if> <c:if test="${!empty userId}">
					<c:if test="${userId == 'admin'}">
						<input type="button" value="글쓰기" onclick="goWrite()" />
					</c:if>
					<c:if test="${m_level == 'b'}">
						<c:if test="${category == 'yagu'||category == 'gallery'}">
							<input type="button" value="글쓰기" onclick="goWrite()" />
						</c:if>
					</c:if>
					<c:if test="${m_level == 'c'}">
						<c:if test="${category == 'yagu'}">
							<input type="button" value="글쓰기" onclick="goWrite()" />
						</c:if>
					</c:if>
			
				</c:if></td>
		</tr>
		<tr>
			<td align="center" colspan="5">${pagingHtml }</td>
		</tr>
		<input type="hidden" value="${team_no}" name="team_no"> 
		<input type="hidden" value="${category}" name="category">
	</form>

	<form action="list.do" name="search" method="post">
	<table width="200" align="center" border="0" cellspacing="0" cellpadding="2"  >
	<tr>
		<td align="center">
			<select name="keyField">
				<option value="bo_title">제목</option>
				<option value="bo_id">이름</option>
				<option value="bo_content">내용</option>
				<option value="all">전체</option>
			</select>
		</td>
		<td>
			<input type="text" size="16" name="keyWord"/>
		</td>
		<td>
			<input type="button" value="찾기" onclick="goSearch()"/>
		</td>
	</tr>
	<!-- team_no랑 category가 필요해서 hidden으로 숨겨두거고. -->
	<input type="hidden" value="${team_no}" name="team_no"> 
	<input type="hidden" value="${category}" name="category">
	<!-- 리턴 category -->
	<input type="hidden" value="<%=category%>" name="category_old">
	
</table>
</form>
</table>
</body>